<script>
	
	export default {
		globalData: {
		  _i18n: {},
		  $t: {},
		  AppLogin:true,//false 未登陆
		  //默认需要添加学生
		  needAddChild:true,
		  //默认不是苹果系统
		  iOSOrAndro:false,
		  appSchoolId:'',
		  stuId:'',
		  userId:'',
		  imService : null,
		  baseUrl:'http://47.100.190.24'
		},
		onReady() {
		   // #ifdef APP-PLUS
		   
		   uni.getStorage({
		   	key:'userName',
			success:(resInfo)=>{
				
				
				
			},
			
		   })
		   // #endif
			
		},
		onLaunch: function() {
			console.log('App Launch')
			this.globalData._i18n = this.$i18n
			this.globalData.$t = str => this.$t(str);
			
			let language = uni.getStorageSync('CURRENT_LANG')
			if (language === 'en') {
			  this.globalData._i18n.locale = 'en'
			} else {
			  this.globalData._i18n.locale = 'zh-CN'
			}
			
			uni.getStorage({
				key:'userId',
				success:(resInfo)=> {
					this.globalData.userId = resInfo.data;
					this.globalData.AppLogin = true;
					this.getuserInfo();
				},
				fail:(err)=>{
					this.globalData.AppLogin = false;
				}
			})
			
			// #ifdef APP-PLUS
			this.lock();
			this.Network();
			this.uniPush();
		   
			  const _self = this;
			   plus.push.addEventListener("receive", function(msg) {  
						// plus.ui.alert(2);  
					// plus.ui.alert("recevice:"+JSON.stringify(msg))
					// plus.nativeUI.toast('push')
					_self.updatePushMessage(msg)
					// _self.handlePush(msg);
			   }, false); 
			// #endif
			
		
			
		},
		onShow: function() {
			console.log('App Show')
			
			
			// #ifdef APP-PLUS
			
			if (plus.navigator.hasNotchInScreen()) {
				
				this.globalData.iOSOrAndro = true

			}
			
			plus.push.clear();
			
			// #endif
			
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			uniPush() {
				
				plus.push.setAutoNotification(true); // 在程序运行时接收到的消息在系统消息中心显示
				//监听接收透传消息事件  
				
				let _self = this
				// plus.push.addEventListener('receive', function(msg) {
				   // 在线消息
				   // console.log('离线消息',msg)
				  // _self.handlePush(msg);
				  // 暂时没用
				 /* let options = {
				    cover: false,
				    sound: 'system',
				    title: msg.title
				  };
				  在线时创建本地通知栏图标消息
				  plus.push.createMessage(msg.content, msg, options); */
				// }, false);
				//监听系统通知栏消息点击事件 
				plus.push.addEventListener('click', function(msg) {
				  // 离线消息
				  // console.log('离线消息',msg)
				  _self.handlePush(msg);
				}, false);
			},
			// 处理通知跳转
			handlePush(msg){
			  if(!msg) return false;
			 //  uni.showModal({
			 //  	title:'调试，这个是消息',
				// content:JSON.stringify(msg),
				// success() {
					
				// }
			 //  })
			  if(msg.payload.path==='msg'){
			    plus.runtime.setBadgeNumber(0); //清除app角标
			    plus.push.clear(); //清空通知栏
			    // console.log('准备跳转');
			    uni.navigateTo({
			    	url:'pages/wuliuList/wuliuList'
			    })
			  }
			},
			// 锁定屏幕方向
			lock() {
			  plus.screen.lockOrientation('portrait-primary'); //锁定
			},
			// 监听网络变化
			Network() {
			  uni.onNetworkStatusChange(function(res) {
			    if (!res.isConnected) {
			      uni.showToast({
			        title: '网络已断开，请重新连接',
			        icon: 'none'
			      })
			    }
			  });
			},
			getuserInfo(){
				uni.getStorage({
					key:'needAddChild',
					success: (resInfo) => {
						
						// console.log('jirul',resInfo)
						if (resInfo.data == '1') {
							// console.log('jirul',resInfo.data.bingdingStudent)
							this.globalData.needAddChild = false
							
							this.globalData.appSchoolId = uni.getStorageSync('appSchoolId');
							this.globalData.stuId = uni.getStorageSync('stuId');
						}
					}
				})

			},
			appUpCid(name){
				const clientInfo = plus.push.getClientInfo()
				console.log('clientInfo',clientInfo);
				let pushUser = {
				  clientid: clientInfo.clientid,
				  appid: clientInfo.appid,
				  appkey: clientInfo.appkey,
				  userName: name,
				  userRole: '客户'
				}
				// 提交api请求，服务端保存客户端角色信息
				Vue.prototype.$minApi.savePushUser(pushUser);
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	/*每个页面公共css */
.ellipsis--1{
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow:ellipsis;
}
.ellipsis--2{
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}
.showZeroMoney{
	font-size: 22rpx;
}
.page{
	background-color: #fff;
	height: 100%;
 }
.showBtnBackColor{
	background: linear-gradient(135deg, #2D63F9 0%, #6421D3 100%);
	box-shadow: 0px 2px 24px 0px rgba(80, 58, 225, 0.36);
}
</style>
